*********************************************************************************
* This is the replication do-file for Replication Data for !Pacified citizens  *
* with a marketized school system: causal evidence of boomeranging effects of  *
* user choice" by Johan Wejryd 								   				   *
*																			   *	
* It is to be run on the accompanying dataset ("Replication Data for Pacified  *
* citizens with a marketized school system.dta")							   *
********************************************************************************


**************************
*Macro for variable list*
**************************

global dvs "inflpolitician infllea inflinspectorate inflmedia inflstamun inflotherparents inflskolrad inflvolontary inflschool"

******************************************
* Settings that are common for all tests *
******************************************

* Setting for robustness (should be either ", robust" which implies applying robust se:s or "" for not applying
global robustness ", robust"

* Setting for outreg-output
global outputchoices "stats(coef se pval) dec(3) excel append"

*** Installing outreg plugin

ssc install outreg2

* Matrix to txt plugin

ssc install mat2txt

set more off

**********************
* Compliance-measure *
**********************

generate compliance=.
replace compliance=0 if treatcheckgr1==1
replace compliance=1 if treatcheckgr1==2
replace compliance=0 if treatcheckgr1==3
replace compliance=0 if treatcheckgr1==4
replace compliance=0 if treatcheckgr2==1
replace compliance=1 if treatcheckgr2==2
replace compliance=0 if treatcheckgr2==3
replace compliance=0 if treatcheckgr2==4
replace compliance=0 if treatcheckgr3==1
replace compliance=1 if treatcheckgr3==2
replace compliance=0 if treatcheckgr3==3
replace compliance=0 if treatcheckgr3==4

*********************
* Attrition-measure *
*********************
generate completer = 0
replace completer = 1 if inflstamun < 8 & inflschool < 8

*******************************
* Manipulation check-measures *
*******************************
	
	* Whether respondent indicated that the scenario gave them user choice *
	* and indpendent school, respectively *

	gen pickedchoice=.
	replace pickedchoice=0 if treatcheckgr1==1
	replace pickedchoice=1 if treatcheckgr1==2
	replace pickedchoice=1 if treatcheckgr1==3
	replace pickedchoice=1 if treatcheckgr2==1
	replace pickedchoice=1 if treatcheckgr2==2
	replace pickedchoice=0 if treatcheckgr2==3
	replace pickedchoice=1 if treatcheckgr3==1
	replace pickedchoice=0 if treatcheckgr3==2
	replace pickedchoice=1 if treatcheckgr3==3

	gen pickedindschool=.
	replace pickedindschool=0 if treatcheckgr1==1
	replace pickedindschool=0 if treatcheckgr1==2
	replace pickedindschool=1 if treatcheckgr1==3
	replace pickedindschool=0 if treatcheckgr2==1
	replace pickedindschool=1 if treatcheckgr2==2
	replace pickedindschool=0 if treatcheckgr2==3
	replace pickedindschool=1 if treatcheckgr3==1
	replace pickedindschool=0 if treatcheckgr3==2
	replace pickedindschool=0 if treatcheckgr3==3

	* Wheteher respondents were correct along each dimension *

	gen pickedcorrectchoice =.
	replace pickedcorrectchoice = 0 if (pickedchoice==0 & choicetreatment==1)
	replace pickedcorrectchoice = 0 if (pickedchoice==1 & choicetreatment==0)
	replace pickedcorrectchoice = 0 if treatcheckgr1==4
	replace pickedcorrectchoice = 0 if treatcheckgr2==4
	replace pickedcorrectchoice = 0 if treatcheckgr3==4
	replace pickedcorrectchoice = 1 if (pickedchoice==0 & choicetreatment==0)
	replace pickedcorrectchoice = 1 if (pickedchoice==1 & choicetreatment==1)

	gen pickedcorrectindschool =.
	replace pickedcorrectindschool = 0 if (pickedindschool==0 & independentschooltreatment==1)
	replace pickedcorrectindschool = 0 if (pickedindschool==1 & independentschooltreatment==0)
	replace pickedcorrectindschool = 0 if treatcheckgr1==4
	replace pickedcorrectindschool = 0 if treatcheckgr2==4
	replace pickedcorrectindschool = 0 if treatcheckgr3==4
	replace pickedcorrectindschool = 1 if (pickedindschool==0 & independentschooltreatment==0)
	replace pickedcorrectindschool = 1 if (pickedindschool==1 & independentschooltreatment==1)


****************
* Use-variable *
****************

generate use=1

* Use-criterion for excluding resp.s treated with "user choice only" from the 
* analyses that test full marketization effect

generate npmuse=1 if use==1
replace npmuse=0 if (choicetreatment==1 & independentschooltreatment==0)


********************************************************************************
*			 							Article								   *
********************************************************************************

************
* Figure 1 *
************

tab choicetreatment independentschooltreatment

****************************************
* Manipulationcheck for each dimension *
****************************************

	* Shares and differences in shares of respondents that indicated correctly 
	* that the scenario gave them user choice and indpendent school, respectively

	tab compliance
	tab pickedcorrectchoice pickedcorrectindschool
	
	prtest pickedcorrectchoice==pickedcorrectindschool, level (90)

*************************************************************
* Initial simple model for the effect of full reform   		*
* including both choice and independent implementors - this *
* is the main model 			                            *
*************************************************************

* Table 1 *

foreach var of varlist $dvs {
reg `var' independentschooltreatment if npmuse==1$robustness
outreg2 using mainmodel, $outputchoices
} 

************************************************
* Accompanying numbers mentioned after Table 1 *
************************************************

* Effect on dichotomized dependent variables *

	foreach var of varlist dichopolitician dicholea dichoinspectorate dichomedia ///
	dichostamun dichootherparents dichoskolrad dichovolontary  dichoschool{
	reg `var' independentschooltreatment if npmuse==1$robust
	outreg2 using modelondichotmousdvs, $outputchoices
	} 

* Effect on number of anticipated actions *
	ttest dichosum if npmuse==1, by(independentschooltreatment) unequal


* Attrition *
	tab completer if use==1

	reg completer independentschooltreatment if npmuse==1$robustness
	outreg2 using attritionnpm, $outputchoices
	reg completer independentschooltreatment if use==1 & choicetreatment==1$robustness
	outreg2 using attritionnpm, $outputchoices
	reg completer choicetreatment if use==1 & independentschooltreatment==0$robustness
	outreg2 using attritionnpm, $outputchoices


**************************************************
* Decomposed model for the respective effects of *
* choice and independent provider 				 *
**************************************************

* Table 2 *

	* Effect of user choice
	foreach var of varlist $dvs {
	reg `var' choicetreatment if use==1 & independentschooltreatment==0 $robustness
	outreg2  using decomposed_model_upper_row, $outputchoices
	}

	* Effect of private provision
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if use==1 & choicetreatment==1 $robustness
	outreg2  using decomposed_model_lower_row, $outputchoices
	}


********************************************************************************
* 							Supporting information 							   *
********************************************************************************

*************************
* PART A - Descriptives *
*************************

* Table 1. Education

tab edu if use==1

* Table 2 Demographic background and political attitudes *

foreach var of varlist positivepolint genderdummyman salienceschoolchoice parentwoschool schoolparent {
sum `var' if use==1
matrix descriptives= (r(mean)), (r(sd)), (r(N))
matrix rownames descriptives= `var'
matrix colnames descriptives= mean sd N
mat2txt, matrix(descriptives) sav("SItable2descriptives.xls") append
} 

* Table 3. Age groups
gen agegroup=.
replace agegroup=6 if age<71
replace agegroup=agegroup-1 if age<65
replace agegroup=agegroup-1 if age<55
replace agegroup=agegroup-1 if age<45
replace agegroup=agegroup-1 if age<35
replace agegroup=agegroup-1 if age<25
tab agegroup if use==1

* Table 4. Resps gross personal monthly income in SEK

tab pinc if use==1

* Table 5. Self-reported left-right postition

gen lrp3=.
replace lrp3=3 if lrpown<11
replace lrp3=2 if lrpown<6
replace lrp3=1 if lrpown<5
tab lrp3 if use==1

*********************************************
* Part B and Table 6 report no calculations *
*********************************************

********************
* Part C - Balance *
********************

* Table 7. *

	global dichobalance "positivepolint parentwoschool schoolparent genderdummyman"
	global intervalbalance "age edu pinc lrpown salienceschoolchoice discussedpolitics demonstrated"

	* Regression with "effect" of full marketization on background variables   

	foreach var of varlist $dichobalance {
	reg `var' independentschooltreatment if npmuse==1$robust
	outreg2 using balancetestnpmcomparison, $outputchoices
	} 
	foreach var of varlist $intervalbalance {
	reg `var' independentschooltreatment if npmuse==1
	outreg2 using balancetestnpmcomparison, $outputchoices
	} 

	* Regression with "effect" of choice-treatment on background variables   

	foreach var of varlist $dichobalance {
	reg `var' choicetreatment if use==1 & independentschooltreatment==0$robust
	outreg2 using balancetestchoicecomparison, $outputchoices
	} 
	foreach var of varlist $intervalbalance {
	reg `var' choicetreatment if use==1  & independentschooltreatment==0
	outreg2 using balancetestchoicecomparison, $outputchoices
	} 
	* Regression with "effect" of independent school-treatment on backgrounds   

	foreach var of varlist $dichobalance {
	reg `var' independentschooltreatment if use==1 & choicetreatment==1$robust
	outreg2 using balancetestindependentcomparison, $outputchoices
	} 
	foreach var of varlist $intervalbalance {
	reg `var' independentschooltreatment if use==1 & choicetreatment==1
	outreg2 using balancetestindependentcomparison, $outputchoices
	} 

*****************************************
* Part D - Principal component analysis *
*****************************************

* Table 8. Principal component analysis

ssc install factortest

factortest inflpolitician infllea inflinspectorate inflmedia inflotherparents ///
inflskolrad inflvolontary if use==1

pca inflpolitician infllea inflinspectorate inflmedia inflotherparents ///
inflskolrad inflvolontary if use==1

***********************
* Part E - Robustness *
***********************

* Table 9 - Robustness to control variables, ordered logistic regression 
* analysis, and to exclusidning non-complying respondents *

	* Model with controls *
	
	global controlson "genderdummyman age age2 i.edu i.muni i.pinc lrpown i.polint parentwoschool schoolparent salienceschoolchoice i.demonstrated i.discussedpolitics"
	
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment $controlson if npmuse==1$robust
	outreg2  using mainmodelwithcontrols, $outputchoices
	} 

	*Ordered logit model wo controls
	foreach var of varlist $dvs {
	ologit `var' i.independentschooltreatment if npmuse==1
	outreg2 using ologit, $outputchoices
	}

	*OLS-model on complying respondents, only*
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if npmuse==1 & compliance==1$robustness
	outreg2 using compliers, $outputchoices
	} 

* Table 10 - Effect of full treatment across the different cities *

	* Stockholm
	foreach var of varlist $dvs {
	reg `var' independent if npmuse==1 & stockholm ==1 $robust
	outreg2 using sthlmmodel, $outputchoices
	} 

	* Gothenburg
	foreach var of varlist $dvs {
	reg `var' independent if npmuse==1 & goteborg ==1 $robust
	outreg2 using gbgmodel, $outputchoices
	} 

	* Malmö
	foreach var of varlist $dvs {
	reg `var' independent if npmuse==1 & malmo ==1 $robust
	outreg2 using malmomodel, $outputchoices
	} 
	
* Table 11. Effects on underrepresented groups

	*Political interest
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if npmuse==1 & (polint==3|polint==4)$robustness
	outreg2  using tehbottompolint, $outputchoices
	} 

	*Personal income
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if npmuse==1 & pinc < 10$robustness
	outreg2  using tehbottompinc, $outputchoices
	} 

	*Left-right position
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if npmuse==1 & lrpown > 4$robustness
	outreg2  using tehlrpright, $outputchoices
	} 

	*education
	foreach var of varlist $dvs {
	reg `var' independentschooltreatment if npmuse==1 & edu<5 $robustness
	outreg2  using tehbottomeducation, $outputchoices
	} 

* END OF DO-FILE
